package com.lc.app.myaccount.helper;

/**
 * Created by LC on 2/5/2016.
 */

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * 创建数据库
 */
public class DBOpenHelper extends SQLiteOpenHelper {
    private static final int VERSION = 1;
    private static final String DBNAME = "account.db";

    public DBOpenHelper(Context context){
        super(context,DBNAME,null,VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        try {
            db.execSQL("create table tb_user (_id integer primary key,name varchar(20),password varchar(20),isadmin integer)");
            db.execSQL("insert into tb_user (name,password,isadmin) values(?,?,?)",new Object[]{"admin","admin",1});
            db.execSQL("create table tb_in_account (_id integer primary key, money decimal, time varchar(10),type varchar(10), handler varchar(100), mark varchar(100),user_id integer )");
            db.execSQL("create table tb_out_account (_id integer primary key, money decimal, time varchar(10),type varchar(10), address varchar(100), mark varchar(100),user_id integer )");

            db.execSQL("create table tb_current (id integer, user varchar(20))");
            Log.d("DBOpenHelper","创建数据库成功");
        }catch (Exception e){
            Log.d("DBOpenHelper Exception","创建数据库失败"+e.getMessage());
        }
    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

//    public void deleteDB(SQLiteDatabase db){
//        try {
//            db.execSQL("drop table tb_user");
//            db.execSQL("drop table tb_in_account");
//            db.execSQL("drop table tb_out_account");
//            db.execSQL("drop table tb_current");
//            Log.d("DBOpenHelper Exception", "删除数据库成功.");
//        }catch (Exception e){
//            Log.d("DBOpenHelper Exception","删除数据库失败."+e.getMessage());
//        }
//
//
//    }

}
